<template>
	<view>
		<view v-for="(item,index) in result.records" :key="index" class="bg-white padding-sm align-center solid-top">
			<view class="flex ">
				<view class="margin-right-sm">
					<view class="cu-tag radius bg-red" v-if="item.status=='ERROR'" @click="showErrorInfo(item)">执行失败</view>
					<view class="cu-tag radius bg-orange" v-if="item.status=='RUNNING'">正在执行</view>
					<view class="cu-tag radius bg-green" v-if="item.status=='SUCCESS'">执行成功</view>
				</view>
				<view class="text-lg text-bold text-cut">{{item.jobName}}</view>
			</view>
			<view class="text-gray margin-top-sm">{{item.startTime}}~{{item.endTime}}</view>
		</view>
		<u-loadmore :status="result.current < result.pages?'loading':'nomore'" />
	</view>
</template>

<script>
export default {
	onLoad: function(option) {
		if (option.jobId) {
			this.page.cond.jobId = option.jobId || '';
			this.list();
		}
	},
	onShow: function() {},
	onReady: function() {},
	onReachBottom: function() {
		if (this.result.current < this.result.pages) {
			this.page.current += 1;
			this.list();
		}
	},
	data() {
		return {
			stickyEnable: false,
			page: {
				current: 1,
				size: 20,
				total: 0,
				orders: [{column: "create_time", asc: false}],
				cond: {jobId: null}
			},
			result: {
				current: 1,
				pages: 1,
				records: []
			},
		};
	},
	methods: {
		// 搜索
		search() {
			this.page.current = 1;
			this.list();
		},
		list() {
			this.$http.post("/admin/sys/scheduler/record/list", this.page, res => {
				let result = res.data || this.result;
				if (this.page.current > 1) {
					result.records = this.result.records.concat(result.records);
				}
				this.result = result;
			}, false, false, true);
		},
		// 显示错误信息
		showErrorInfo(item) {
			uni.navigateTo({
				url: `error-info?id=${item.id}`
			});
		}
	}
}
</script>

<style lang="scss" scoped>
</style>
